package com.smallframework.demo.controller;

import com.smallframework.demo.domain.User;
import com.smallframework.demo.service.UserService;
import com.smallframework.mvc.Controller;
import com.smallframework.mvc.Inject;
import com.smallframework.mvc.RequestMapping;
import com.smallframework.mvc.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 * User: Administrator
 * DateTime: 2017/7/2 0002 13:24
 */
@Controller
@RequestMapping("/user")
public class UserController {
	@Inject
	private UserService userService;

	@RequestMapping("/add")
	public String add() {
		userService.createUser();
		return "success";
	}

	@RequestMapping("/create")
	public String create(String name, int age) {
		userService.createUser(name, age);
		return "success";
	}

	@RequestMapping("/find")
	@ResponseBody
	public Map<String, Object> find() {
		User user = new User();
		user.setName("tan");
		user.setAge(20);

		Map<String, Object> data = new HashMap<>();
		data.put("user", user);
		return data;
	}

	@RequestMapping("/index")
	public String index(HttpServletRequest request) {
		request.setAttribute("name", "tanhaiyuan");
		return "index.jsp";
	}
}
